package com.akk.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 * 
 */
public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public static String SUCCESS = "200";
	public static String ERROR_ONE = "2001";





	public R() {
		put("code",SUCCESS);
		put("msg","");
		put("data",null);
	}
	
	public static R error() {
		return error("未知的系统异常.");
	}

	public static R error (String msg) {
		R r = new R();
		r.put("code",ERROR_ONE);
		r.put("msg",msg);
		r.put("data",null);
		return r;
	}

	public static R error(String msg, Object o) {
		R r = new R();
		r.put("code", ERROR_ONE);
		r.put("msg", msg);
		r.put("data",o);
		return r;
	}
	public static R error(String code, String msg, Object o){
		R r = R.error(msg,o);
		r.put("code", code);
		return r;
	}

	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}
	public static R ok(String msg, Object o) {
		R r = new R();
		r.put("msg",msg);
		r.put("data",o);
		return r;
	}
	public static R ok(Object o) {
		return R.ok("",o);
	}


	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}
	
	public static R ok() {
		return new R();
	}

	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
